package cn.net.sinodata.common.core.enums;

import cn.net.sinodata.common.core.domain.R;

/**
 * 分布式锁对应的枚举类
 */
public enum LockKeyEnum {
    GET_MSG_RECORD_LOCK("GET_MSG_RECORD_LOCK", "获取待解析报文记录");

    public final String code;
    public final String msg;

    LockKeyEnum(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    /**
     * 通过code获取对应实例
     * @param code
     * @return
     */
    public static R<LockKeyEnum> getInstance(String code) {
        LockKeyEnum[] values = values();
        for (LockKeyEnum value : values()) {
            if (value.equals(code)) {
                return R.ok(value);
            }
        }
        return R.fail();
    }

    /**
     * 自定义equals
     * @param code
     * @return
     */
    public boolean equalsCode(String code) {
        return this.code.equals(code) ? true : false;
    }

    @Override
    public String toString() {
        return "[code="+code+",msg="+msg+"]";
    }
}
